<template>
  <div>
    <el-col :span="12">
      <el-form-item :label="$t('一级行业')" prop="industryFirst">
        <el-select v-model="bussData.industryFirst" value="" :clearable="true" :placeholder="$t('一级行业')" @change="industryChanged">
          <el-option
            v-for="si in industryFirstOptions"
            :key="si.id"
            :label="$t(si.name)"
            :value="si.id"
          />
        </el-select>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item :label="$t('二级行业')" prop="industrySecond">
        <el-select v-model="bussData.industrySecond" value="" :clearable="true" :placeholder="$t('二级行业')">
          <el-option
            v-for="si in industrySecondOptions"
            :key="si.id"
            :label="$t(si.name)"
            :value="si.id"
          />
        </el-select>
      </el-form-item>
    </el-col>
  </div>
</template>
<script>
  import { allFirstList, getSecondList } from '@/api/system/industry/sysIndustry'
  export default {
    name: 'Industry',
    props: {
      // 一级行业
      bussData: {
        type: Object,
        required: true
      }
    },
    data: () => {
      return {
        // 二级行业
        industrySecondOptions: [],
        // 一级行业
        industryFirstOptions: []
      }
    },
    created() {
      // 获取所有的一级行业集合
      allFirstList().then(response => {
        this.industryFirstOptions = response.data
      })
    },
    methods: {
      industryChanged() {
        getSecondList(this.bussData.industryFirst).then(res => {
          this.bussData.industrySecond = ''
          this.industrySecondOptions = res.data
        })
      },
      initIndustrySecond() {
        if (this.bussData.industryFirst !== null && this.bussData.industryFirst !== '') {
          getSecondList(this.bussData.industryFirst).then(res => {
            this.industrySecondOptions = res.data
          })
        }
      },
      // 表单重置
      reset() {
        this.industrySecondOptions = []
      }

    }
  }
</script>
